package com.ctg.sysmgr.sso.server.control.view;



import org.springframework.webflow.core.collection.MutableAttributeMap;
import org.springframework.webflow.execution.Event;
import org.springframework.webflow.execution.RequestContext;


public class DefaultRedirectAction {

	/** Authentication success result. */
    public static final String TRUE = "true";
    public static final String FALSE = "false";
    
    private String needRedirect;
    private String redirectUrl;
    
    public final void setNeedRedirect(final String needRedirect){  
        this.needRedirect = needRedirect; 
    } 
    
    public final void setRedirectUrl(final String redirectUrl){  
        this.redirectUrl = redirectUrl; 
    }
    
	public final Event converViewUrl(final RequestContext context) {
		MutableAttributeMap<Object> scope = context.getRequestScope();

		if("1".equals(needRedirect) && null != redirectUrl) {
			scope.put("redirectUrl", redirectUrl);
			return newEvent(TRUE);
		}
		
		return newEvent(FALSE);
	}
	
	/**
     * New event based on the given id.
     *
     * @param id the id
     * @return the event
     */
    private Event newEvent(final String id) {
        return new Event(this, id);
    }
}
